/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2012-2021. All rights reserved.
 */

package com.huawei.chengdu.meetingdemo.view.dialogs;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Toast;

import com.huawei.chengdu.meetingdemo.view.IViewDataObserver;

/**
 * 类名：BaseView
 * 描述：基准View
 */
public abstract class BaseView implements IViewDataObserver {
    /**
     * 上下文
     */
    protected Context mContext;

    /**
     * view根布局
     */
    protected View mRootView;

    public BaseView(Context context) {
        mContext = context;
        initRootView();
    }

    private void initRootView() {
        mRootView = LayoutInflater.from(mContext).inflate(getLayoutId(), null);
    }

    /**
     * 获取布局画面
     *
     * @return 画面
     */
    public View getLayoutView() {
        return mRootView;
    }

    /**
     * 获取跟布局id
     *
     * @return 布局id
     */
    protected abstract int getLayoutId();

    /**
     * 销毁
     */
    public void destroy() {
        unRegisterListenService();
        mRootView = null;
        mContext = null;
    }

    protected void updateToast(String str) {
        new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(mContext, str, Toast.LENGTH_SHORT).show());
    }

    protected void updateToast(int id) {
        new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(mContext, id, Toast.LENGTH_SHORT).show());
    }
}
